There are five possible command-line arguments:
Global flags are declared for each of the arguments. @d Global variable dec... @extern int tex_flag; /* if FALSE, don't emit the .tex file */ extern int output_flag; /* if FALSE, don't emit the output files */ extern int compare_flag; /* if FALSE, overwrite without comparison */ extern int verbose_flag; /* if TRUE, write progress information */ extern int number_flag; /* if TRUE, use a sequential numbering scheme */ @| tex_flag output_flag compare_flag verbose_flag number_flag @
The flags are all initialized for correct default behavior.
@d Global variable def... @int tex_flag = TRUE; int output_flag = TRUE; int compare_flag = TRUE; int verbose_flag = FALSE; int number_flag = FALSE; @
We save the invocation name of the command in a global variable
command_name
for use in error messages.
@d Global variable dec...
@extern char *command_name;
@| command_name @
@d Global variable def... @char *command_name = NULL; @
The invocation name is conventionally passed in argv[0]
.
@d Interpret com...
@command_name = argv[0];
@
We need to examine the remaining entries in argv
, looking for
command-line arguments.
@d Interpret com...
@while (arg < argc)
char *s = argv[arg];
if (*s++ == '-')
@<Interpret the argument string s
@>
arg++;
else break;
@
Several flags can be stacked behind a single minus sign; therefore, we've got to loop through the string, handling them all. @d Interpret the... @ char c = *s++; while (c) switch (c) case 'c': compare_flag = FALSE; break; case 'n': number_flag = TRUE; break; case 'o': output_flag = FALSE; break; case 't': tex_flag = FALSE; break; case 'v': verbose_flag = TRUE; break; default: fprintf(stderr, "command_name); fprintf(stderr, "Usage is: command_name); break; c = *s++; @